<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <base href="<%=basePath%>">   
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>标题</title>  
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

	<script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>	

	</head>
<body>
<script>
function ajax1(){
	// $('#form1').serialize()
	var datajson={"name":"a"};
	   $.ajax({
           //几个参数需要注意一下
               type: "POST",//方法类型            
               url: "demolist1.do" ,//url
               data:datajson,
               success: function (result) {
                   console.log(result);//打印服务端返回的数据(调试用)
                 
                   $('#otext').val( JSON.stringify(result));
                                   
               },
               error : function() {
                   alert("异常！");
               }
           });
}
function ajax2(){
	var datajson={"name":"2"};
	 $.ajax({
         //几个参数需要注意一下
             type: "POST",//方法类型
             contentType: "application/json;charset=UTF-8",//请求数据类型
             dataType:"json" ,//预期服务器返回的数据类型 默认是json对象
             url: "demolist2.do" ,//url
             data: JSON.stringify(datajson),
             success: function (result) {
                 console.log(result);//打印服务端返回的数据(调试用)
                 $('#otext').val( JSON.stringify(result));
                 
             },
             error : function() {
                 alert("异常！");
             }
         });
}
</script>

<form>
<textarea id="otext" style="width:600px;height:300px">  </textarea>
</form>
<a href="javascript:ajax1()">提交ajax1</a><br>
<a href="javascript:ajax2()">提交ajax2</a>
</body>
</html>


